﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using MvcApplication4.Models;
using Syncfusion.DocIO.DLS;
using Syncfusion.Mvc.Grid;
using Syncfusion.Pdf;
using Syncfusion.XlsIO;

namespace MvcApplication4.Controllers
{
    public class CadastroLoteController : Controller
    {
        private BD_Vacinas2Context db = new BD_Vacinas2Context();

        //
        // GET: /CadastroLote/

        public ActionResult Index()
        {
            var data = new MvcApplication4.Models.BD_Vacinas2Context().LOTEs.Take(100).ToList();
            return View(data);
        }

        [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult Index(PagingParams args)
        {
            IEnumerable data = new MvcApplication4.Models.BD_Vacinas2Context().LOTEs.Take(100).ToList();
            return data.GridActions<LOTE>();
        }

        public ActionResult ExportToExcel()
        {
            var data = new MvcApplication4.Models.BD_Vacinas2Context().LOTEs.Take(200).ToList();
            return data.GridExportToExcel<LOTE>("GridExcel.xlsx", ExcelVersion.Excel2010);
        }

        public ActionResult ExportToWord(PagingParams args)
        {
            var data = new MvcApplication4.Models.BD_Vacinas2Context().LOTEs.Take(200).ToList();
            return data.GridExportToWord<LOTE>("GridWord.doc", DocumentVersion.Word2007, args.ExportOption);
        }

        public ActionResult ExportToPDF(PagingParams args)
        {
            var data = new MvcApplication4.Models.BD_Vacinas2Context().LOTEs.Take(200).ToList();
            return data.GridExportToPDF<LOTE>("GridPDF.pdf", PdfVersion.Version1_7, args.ExportOption);
        }

        //
        // GET: /CadastroLote/Details/5

        public ActionResult Details(string id = null)
        {
            LOTE lote = db.LOTEs.Find(id);
            if (lote == null)
            {
                return HttpNotFound();
            }
            return View(lote);
        }

        //
        // GET: /CadastroLote/Create

        public ActionResult Create()
        {
            ViewBag.ID_Laboratorio = new SelectList(db.tb_Laboratorio, "ID_Laboratorio", "Nome_Laboratorio");
            ViewBag.ID_Vacina = new SelectList(db.tb_Vacina, "ID_Vacina", "Nome_Vacina");
            return View();
        }

        //
        // POST: /CadastroLote/Create

        [HttpPost]
        public ActionResult Create(LOTE lote)
        {
            if (ModelState.IsValid)
            {
                db.LOTEs.Add(lote);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            ViewBag.ID_Laboratorio = new SelectList(db.tb_Laboratorio, "ID_Laboratorio", "Nome_Laboratorio", lote.ID_Laboratorio);
            ViewBag.ID_Vacina = new SelectList(db.tb_Vacina, "ID_Vacina", "Nome_Vacina", lote.ID_Vacina);
            return View(lote);
        }

        //
        // GET: /CadastroLote/Edit/5

        public ActionResult Edit(string id = null)
        {
            LOTE lote = db.LOTEs.Find(id);
            if (lote == null)
            {
                return HttpNotFound();
            }
            ViewBag.ID_Laboratorio = new SelectList(db.tb_Laboratorio, "ID_Laboratorio", "Nome_Laboratorio", lote.ID_Laboratorio);
            ViewBag.ID_Vacina = new SelectList(db.tb_Vacina, "ID_Vacina", "Nome_Vacina", lote.ID_Vacina);
            return View(lote);
        }

        //
        // POST: /CadastroLote/Edit/5

        [HttpPost]
        public ActionResult Edit(LOTE lote)
        {
            if (ModelState.IsValid)
            {
                db.Entry(lote).State = EntityState.Modified;
                db.SaveChanges();
                return RedirectToAction("Index");
            }
            ViewBag.ID_Laboratorio = new SelectList(db.tb_Laboratorio, "ID_Laboratorio", "Nome_Laboratorio", lote.ID_Laboratorio);
            ViewBag.ID_Vacina = new SelectList(db.tb_Vacina, "ID_Vacina", "Nome_Vacina", lote.ID_Vacina);
            return View(lote);
        }

        //
        // GET: /CadastroLote/Delete/5

        public ActionResult Delete(string id = null)
        {
            LOTE lote = db.LOTEs.Find(id);
            if (lote == null)
            {
                return HttpNotFound();
            }
            return View(lote);
        }

        //
        // POST: /CadastroLote/Delete/5

        [HttpPost, ActionName("Delete")]
        public ActionResult DeleteConfirmed(string id)
        {
            LOTE lote = db.LOTEs.Find(id);
            db.LOTEs.Remove(lote);
            db.SaveChanges();
            return RedirectToAction("Index");
        }

        protected override void Dispose(bool disposing)
        {
            db.Dispose();
            base.Dispose(disposing);
        }
    }

    public class CopyOfCadastroLoteController : Controller
    {
        private BD_Vacinas2Context db = new BD_Vacinas2Context();

        //
        // GET: /CadastroLote/

        public ActionResult Index()
        {
            var data = new MvcApplication4.Models.BD_Vacinas2Context().LOTEs.Take(100).ToList();
            return View(data);
        }

        [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult Index(PagingParams args)
        {
            IEnumerable data = new MvcApplication4.Models.BD_Vacinas2Context().LOTEs.Take(100).ToList();
            return data.GridActions<LOTE>();
        }

        public ActionResult ExportToExcel()
        {
            var data = new MvcApplication4.Models.BD_Vacinas2Context().LOTEs.Take(200).ToList();
            return data.GridExportToExcel<LOTE>("GridExcel.xlsx", ExcelVersion.Excel2010);
        }

        public ActionResult ExportToWord(PagingParams args)
        {
            var data = new MvcApplication4.Models.BD_Vacinas2Context().LOTEs.Take(200).ToList();
            return data.GridExportToWord<LOTE>("GridWord.doc", DocumentVersion.Word2007, args.ExportOption);
        }

        public ActionResult ExportToPDF(PagingParams args)
        {
            var data = new MvcApplication4.Models.BD_Vacinas2Context().LOTEs.Take(200).ToList();
            return data.GridExportToPDF<LOTE>("GridPDF.pdf", PdfVersion.Version1_7, args.ExportOption);
        }

        //
        // GET: /CadastroLote/Details/5

        public ActionResult Details(string id = null)
        {
            LOTE lote = db.LOTEs.Find(id);
            if (lote == null)
            {
                return HttpNotFound();
            }
            return View(lote);
        }

        //
        // GET: /CadastroLote/Create

        public ActionResult Create()
        {
            ViewBag.ID_Laboratorio = new SelectList(db.tb_Laboratorio, "ID_Laboratorio", "Nome_Laboratorio");
            ViewBag.ID_Vacina = new SelectList(db.tb_Vacina, "ID_Vacina", "Nome_Vacina");
            return View();
        }

        //
        // POST: /CadastroLote/Create

        [HttpPost]
        public ActionResult Create(LOTE lote)
        {
            if (ModelState.IsValid)
            {
                db.LOTEs.Add(lote);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            ViewBag.ID_Laboratorio = new SelectList(db.tb_Laboratorio, "ID_Laboratorio", "Nome_Laboratorio", lote.ID_Laboratorio);
            ViewBag.ID_Vacina = new SelectList(db.tb_Vacina, "ID_Vacina", "Nome_Vacina", lote.ID_Vacina);
            return View(lote);
        }

        //
        // GET: /CadastroLote/Edit/5

        public ActionResult Edit(string id = null)
        {
            LOTE lote = db.LOTEs.Find(id);
            if (lote == null)
            {
                return HttpNotFound();
            }
            ViewBag.ID_Laboratorio = new SelectList(db.tb_Laboratorio, "ID_Laboratorio", "Nome_Laboratorio", lote.ID_Laboratorio);
            ViewBag.ID_Vacina = new SelectList(db.tb_Vacina, "ID_Vacina", "Nome_Vacina", lote.ID_Vacina);
            return View(lote);
        }

        //
        // POST: /CadastroLote/Edit/5

        [HttpPost]
        public ActionResult Edit(LOTE lote)
        {
            if (ModelState.IsValid)
            {
                db.Entry(lote).State = EntityState.Modified;
                db.SaveChanges();
                return RedirectToAction("Index");
            }
            ViewBag.ID_Laboratorio = new SelectList(db.tb_Laboratorio, "ID_Laboratorio", "Nome_Laboratorio", lote.ID_Laboratorio);
            ViewBag.ID_Vacina = new SelectList(db.tb_Vacina, "ID_Vacina", "Nome_Vacina", lote.ID_Vacina);
            return View(lote);
        }

        //
        // GET: /CadastroLote/Delete/5

        public ActionResult Delete(string id = null)
        {
            LOTE lote = db.LOTEs.Find(id);
            if (lote == null)
            {
                return HttpNotFound();
            }
            return View(lote);
        }

        //
        // POST: /CadastroLote/Delete/5

        [HttpPost, ActionName("Delete")]
        public ActionResult DeleteConfirmed(string id)
        {
            LOTE lote = db.LOTEs.Find(id);
            db.LOTEs.Remove(lote);
            db.SaveChanges();
            return RedirectToAction("Index");
        }

        protected override void Dispose(bool disposing)
        {
            db.Dispose();
            base.Dispose(disposing);
        }
    }
}